package bookSystemDao.impl;

import bookSystemDao.BookStoreDao;
import bookSystemEntity.BookStoreEntity;
import tool.BaseDao;

import java.sql.ResultSet;
import java.sql.SQLException;

public class BookStoreImpl extends BaseDao implements BookStoreDao {

    @Override
    public int Login(BookStoreEntity book) {
        ResultSet rs=null;
        int count=0;
        try {
            String sql="select count(*) from admin where adminName=? and adminPwd=?";
            Object pare[]={book.getName(),book.getPwd()};
           rs=super.executeQuery(sql,pare);
            if (rs.next()){
                //拿到查询结果
                count=rs.getInt(1);
            }
        } catch (SQLException e) {
            System.err.println("数据访问层"+e);
        }
        return count;
    }

    @Override
    public int Regist(BookStoreEntity book) {
        int count=0;
        try {
            String sql="insert into `admin`(`adminPwd`,`adminPhone`,permissions)values(?,?,?)";
            Object[]pare={book.getPwd(),book.getPhone(),book.getPermiss()};
            count=super.executeUpdate(sql,pare);
        } catch (Exception e) {
            System.err.println("数据访问层"+e);
        }
        return count;
    }
}
